home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / barbu2 / str.hpp < prev   
C/C++ Source or Header  |  1995-05-07  |  2KB  |  63 lines

  1. //////////////////////////////////////////////////////
  2. //    STR.HPP    Null-Ended String Class
  3. //////////////////////////////////////////////////////
  4. #if !defined(STR_HPP)
  5. #define STR_HPP
  6. #include <string.h>
  7.  
  8. /**
  9. #include "AFC.HPP"
  10. extern TRACER* t;
  11. **/
  12.  
  13. class STR {
  14.     char *s;    // free store pointer
  15.     int  l;        // strlen + 1
  16.  
  17. public:
  18.     STR();                    // STR Dummy; l=1
  19.     STR(const STR&);
  20.     STR(const char szS[]);    // STR V("abc"); l=4
  21.     STR(int);                  // STR V(25); s[0]=0, l=26
  22.     ~STR();
  23.  
  24.     operator const char* () const { return s; }
  25.     int len() const { return strlen(s); }
  26.     int space() const { return l-1; }
  27.  
  28.     STR& operator=(const STR &y);
  29.     STR& operator+=(const STR &y);
  30.     int operator==(const STR &y) const
  31.             { return (0 == strcmp(s, y.s)); }
  32.     int operator!=(const STR &y) const
  33.             { return (0 != strcmp(s, y.s)); }
  34.  
  35.     STR& operator=(const char szS[]);
  36.     STR& operator+=(const char szS[]);
  37.     int operator==(const char szS[]) const
  38.             { return (0 == strcmp(s, szS)); }
  39.     int operator!=(const char szS[]) const
  40.             { return (0 != strcmp(s, szS)); }
  41.  
  42.     STR& operator=(char c);
  43.     STR& operator+=(char c);
  44.  
  45.     char& operator[](int i) { return s[i]; }
  46.     const char& operator[](int i) const
  47.             { return s[i]; }
  48.  
  49.     int streq(const char szS[]) const;
  50.     int hasin(const char szSubstring[],
  51.             int nFromIndex = 0, int bIgnoreCase = 0
  52.             ) const ;// returns absolute index or -1
  53.     int hasin(char c,
  54.             int nFromIndex = 0, int bIgnoreCase = 0
  55.             ) const ;// returns absolute index or -1
  56.  
  57.     STR& toupper() { strupr(s); return *this; }
  58.     STR& tolower() { strlwr(s); return *this; }
  59.     void noFrontSpace();    // "  \t\nabc" --> "abc"
  60.     void noTrailSpace();    // "abc  \t\n " --> "abc"
  61. };
  62. #endif
  63.